package Teste;

import java.awt.Color;
import java.awt.Container;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.math.array.DoubleArray;
import org.math.plot.*;

public class GridPlotsExample {
	static Plot3DPanel plot = new Plot3DPanel();
	static int idPoint = 0;

	public static void main(String[] args) {
		double[] x = DoubleArray.increment(0.0, 0.1, 1.0);
		double[] y = DoubleArray.increment(0.0, 0.1, 1.0);

		JSlider slider = new JSlider(0,6,0);
		slider.setBorder(BorderFactory.createTitledBorder("Passo a Passo"));
		slider.setMajorTickSpacing(1);
		slider.setMinorTickSpacing(1);
		slider.setPaintTicks(true);
		slider.setPaintLabels(true);
		
		// create your PlotPanel (you can use it as a JPanel) with a legend at SOUTH
		
		//plot.getAxis(0).setGridVisible(false);
		//plot.getAxis(1).setGridVisible(false);
		//plot.getAxis(2).setGridVisible(false);

		//plot.addHyperboloidTwoSheetPlot("HyperboloidTwoSheet", Color.blue, 0.5, 0.6, 1.0);
		//plot.addHyperboloidOneSheetPlot("HyperboloidOneSheet", Color.blue, 0.5, 0.6, 0.8);
		//plot.addEllipsoidPlot("Ellipsoid", Color.blue, 0.6, 0.9, 0.5);
		//plot.addHyperbolicParaboloidPlot("HyperbolicParaboloid", Color.blue, 0.7, 0.8);
		//plot.addEllipticParaboloidPlot("EllipticParaboloid", Color.red, 0.7, 0.8);
		//plot.addConePlot("Cone", Color.blue, 0.5, 1);
		//plot.addCylinderPlot("Cylinder", Color.green, 0.5, 1);
		plot.addSpherePlot("Sphere", Color.red, 1.0);
		//plot.addPlanePlot("Plane1", Color.black, 1, 1, 1, 0);
		//plot.addPlanePlot("Plane2", Color.black, 1, 1, 1, 0);
		//plot.addPlanesIntersectionPlot("Plane", Color.blue, new double[] {1, -1, 1, 0}, new double[] {1, 1, 1, 0});
		//idPoint = plot.addPointPlot("Point", Color.yellow, 0, 0, 0);
		//plot.getPlot(idPoint).addVector(new double[][] {{1,1,1}});
		//plot.addLabel("u", Color.yellow, 0, 0, 0.1);
		
		// put the PlotPanel in a JFrame like a JPanel
		JFrame frame = new JFrame("a plot panel");
		frame.setSize(600, 600);
		Container tela = frame.getContentPane();
		
		//frame.setContentPane(plot);
		BoxLayout boxLayout = new BoxLayout(tela, BoxLayout.Y_AXIS);
		tela.setLayout(boxLayout);
		
		tela.add(plot);
		tela.add(slider);
		
		slider.addChangeListener(new ChangeListener(){
			
			@Override
		    public void stateChanged(ChangeEvent e) {
		       
				JSlider source = (JSlider)e.getSource();
				System.out.println(source.getValue());
				
				plot.getPlot(idPoint).setData(new double[][] {{source.getValue()/10.0, 0.5, 0.5}});
				
				//point3D.setCoordenate(source.getValue()/10.0, 0.5, 0.5);
				//sphere.setRatio(source.getValue()/10.0);
				
				plot.repaint();

		    }
		});
		

		frame.setVisible(true);

	}
	
	public static double[][] Paraboloide (double a, double b, double[] _x, double[] _y){
		
		double[][] z = new double[_x.length][_y.length]; 
		for (int i = 0; i < _x.length; i++){
			for (int j = 0; j < _y.length; j++){
				z[i][j] = Math.pow(_x[i]/a, 2) + Math.pow(_y[i]/b, 2);
			}
		}
		return z;
		
	}
}